using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Entropy3D.Graphics;
using Entropy3D.View;

namespace Entropy3D
{
    public class Engine
    {
        private GraphicsDeviceManager manager;
        public GraphicsDeviceManager Manager
        {
            get { return manager; }
        }

        private Camera camera;
        public Camera Camera
        {
            get { return camera; }
        }

        public Engine(GraphicsDeviceManager manager)
        {
            this.manager = manager;
            camera = new Camera(this);
        }

        private float drawCallTime = 0f;
        public float DrawCallTime
        {
            get { return drawCallTime; }
        }

        // Prepares all the objects for a draw call.
        // Should be called first on a draw cycle.
        public void PrepareObjects()
        {
            foreach (GraphicsObject go in Pool.Objects)
            {
                go.Prepare();
            }
        }

        public void Update(GameTime gameTime)
        {
            camera.Update(gameTime);
        }

        public void Draw(GameTime gameTime)
        {
            drawCallTime = 0f;

            DateTime drawStart = DateTime.Now;

            foreach (GraphicsObject go in Pool.Objects)
            {
                go.Draw(camera.View, camera.Projection);
            }

            DateTime drawEnd = DateTime.Now;

            TimeSpan duration = drawEnd - drawStart;

            drawCallTime = (float)duration.TotalMilliseconds;
        }

    }
}
